﻿using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualBasic.ApplicationServices;

namespace QuickTuner.Util
{
    /// <summary>
    /// Provides instance-controlling services.
    /// </summary>
    /// <remarks>
    /// Creation of main form is deferred it is sure that an instance is not already running.
    /// </remarks>
    public class InstanceController : WindowsFormsApplicationBase
    {
        Func<Form> _mainFormCreator;

        public InstanceController(Func<Form> createMainFormFunction, bool isSingleInstance)
        {
            this.IsSingleInstance = IsSingleInstance;
            _mainFormCreator = createMainFormFunction;
        }

        protected override void OnCreateMainForm()
        {
            this.MainForm = _mainFormCreator();

            base.OnCreateMainForm();
        }
    }
}
